/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(){
	var vpclassmod = parseInt($("#vpclassmodifier").html());
	var vpconstmod = parseInt($("#vpconstitutionmodifier").html());
	var vpclasslvl = parseInt($("#vpclasslevel").html());
	var vpsub = vpclassmod + vpconstmod;
	var vptotal = vpsub * vpclasslvl;
	$("#vptotal").html(vptotal);
        $(".current-vitality").html(vptotal);
	
	var wpconst = parseInt($("#wpconstitution").html());
	var wpmiscmod = parseInt($("#wpmiscmod").html());
	var wptotal = wpconst + wpmiscmod;
	$("#wptotal").html(wptotal);
        $(".current-wound").html(wptotal);
	
	var spclassmod = parseInt($("#spclassmodifier").html());
	var spconstmod = parseInt($("#spconstitutionmodifier").html());
	var spclasslvl = parseInt($("#spclasslevel").html());
	var spsub = spclassmod + spconstmod;
	var sptotal = spsub * spclasslvl;
	$("#sptotal").html(sptotal);
        $(".current-subdual").html(sptotal);
	
	var mpclassmod = parseInt($("#mpclassmodifier").html());
	var mpclasslvl = parseInt($("#mpclasslevel").html());
	var mptotal = mpclassmod * mpclasslvl;
	$("#mptotal").html(mptotal);
        $(".current-mana").html(mptotal);


    $("button#vitality-1").click(function(e){
        if ($("span.current-vitality").html()>0) {
            $("span.current-vitality").html(+$("span.current-vitality").html()-1);
        } else {
            alert("Not enough Vitality Points");
        }
    });
    $("button#vitality-5").click(function(e){
        if ($("span.current-vitality").html()>4) {
            $("span.current-vitality").html(+$("span.current-vitality").html()-5);
        } else {
            alert("Not enough Vitality Points");
        }
    });
    $("button#vitality-10").click(function(e){
        if ($("span.current-vitality").html()>9) {
            $("span.current-vitality").html(+$("span.current-vitality").html()-10);
        } else {
            alert("Not enough Vitality Points");
        }
    });
    $("button#vitality-reset").click(function(e){
            $("span.current-vitality").html($("#vptotal").html());
    });
    $("button#wound-1").click(function(e){
        if ($("span.current-wound").html()>0) {
            $("span.current-wound").html(+$("span.current-wound").html()-1);
        } else {
            alert("Not enough wound Points");
        }
    });
    $("button#wound-5").click(function(e){
        if ($("span.current-wound").html()>4) {
            $("span.current-wound").html(+$("span.current-wound").html()-5);
        } else {
            alert("Not enough wound Points");
        }
    });
    $("button#wound-10").click(function(e){
        if ($("span.current-wound").html()>9) {
            $("span.current-wound").html(+$("span.current-wound").html()-10);
        } else {
            alert("Not enough wound Points");
        }
    });
    $("button#wound-reset").click(function(e){
            $("span.current-wound").html($("#wptotal").html());
    });
    $("button#subdual-1").click(function(e){
        if ($("span.current-subdual").html()>0) {
            $("span.current-subdual").html(+$("span.current-subdual").html()-1);
        } else {
            alert("Not enough subdual Points");
        }
    });
    $("button#subdual-5").click(function(e){
        if ($("span.current-subdual").html()>4) {
            $("span.current-subdual").html(+$("span.current-subdual").html()-5);
        } else {
            alert("Not enough subdual Points");
        }
    });
    $("button#subdual-10").click(function(e){
        if ($("span.current-subdual").html()>9) {
            $("span.current-subdual").html(+$("span.current-subdual").html()-10);
        } else {
            alert("Not enough subdual Points");
        }
    });
    $("button#subdual-reset").click(function(e){
            $("span.current-subdual").html($("#sptotal").html());
    });
    $("button#mana-1").click(function(e){
        if ($("span.current-mana").html()>0) {
            $("span.current-mana").html(+$("span.current-mana").html()-1);
        } else {
            alert("Not enough mana Points");
        }
    });
    $("button#mana-5").click(function(e){
        if ($("span.current-mana").html()>4) {
            $("span.current-mana").html(+$("span.current-mana").html()-5);
        } else {
            alert("Not enough mana Points");
        }
    });
    $("button#mana-10").click(function(e){
        if ($("span.current-mana").html()>9) {
            $("span.current-mana").html(+$("span.current-mana").html()-10);
        } else {
            alert("Not enough mana Points");
        }
    });
    $("button#mana-reset").click(function(e){
            $("span.current-mana").html($("#mptotal").html());
    });
    
    $("#next").click(function(e){
        $("#charinfo").slideUp();
        $("#charabilities").slideDown();
        $("#previous").show();
        $("#next2").show();
        $("#next").hide();
    })
    $("#next2").click(function(e){
        $("#charabilities").slideUp();
        $("#charparty").slideDown();
        $("#previous2").show();
        $("#next2").hide();
        $("#previous").hide();
        $("#save").show();
    })
    $("#previous").click(function(e){
        $("#charabilities").slideUp();
        $("#charinfo").slideDown();
        $("#next").show();
        $("#next2").hide();
        $("#previous").hide();
    })
    $("#previous2").click(function(e){
        $("#charparty").slideUp();
        $("#charabilities").slideDown();
        $("#previous2").hide();
        $("#next2").show();
        $("#previous").show();
        $("#save").hide();
    })
    $("#save").click(function(e) {
        $("[name=charinfo]").submit();
    })
});